
cc.Class({
    extends: cc.Component,

    properties: {
        propPrefab: cc.Prefab,
        propJson: cc.JsonAsset,
    },


    onLoad() {
        this.schedule(this.createProp, 4);
    },

    start() {

    },

    update(dt) {

    },

    //创建道具
    createProp() {
        let propNode = cc.instantiate(this.propPrefab);
        propNode.parent = this.node;
        let minX = -cc.winSize.width / 2 + propNode.width / 2;
        let maxX = cc.winSize.width / 2 - propNode.width / 2;
        propNode.x = Math.random() * (maxX - minX) + minX;
        propNode.y = cc.winSize.height / 2 + propNode.height;
        let propNodeJs = propNode.getComponent("Prop");
        //随机propDt中的一条数据
        let index = Math.floor(Math.random() * (this.propJson.json.length - 0) + 0);
        let propDt = this.propJson.json[index];
        //将这条数据（是一个对象）传入到Prop脚本中
        propNodeJs.initPropDt(propDt);
        propNodeJs.propMove();
    }
});
